﻿using System;
using NUnit.Framework;
using System.Collections.Generic;
using ScrappyDB.Utilities;

namespace ScrappyDB.UnitTests
{
    
    
    /// <summary>
    ///This is a test class for UtilityTest and is intended
    ///to contain all UtilityTest Unit Tests
    ///</summary>
    [TestFixture()]
    public class UtilityTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        /// <summary>
        ///A test for CleanTags
        ///</summary>
        [Test()]
        public void CleanTagsTest()
        {
            var distinct = new List<string>() {"a", "dog", "ate", "the", "cat"};
            List<string> actual;
            actual = Utility.CleanTags(distinct);
            Assert.AreEqual(3, actual.Count);
            Assert.IsTrue(actual.Contains("cat"));
            Assert.IsTrue(!actual.Contains("the"));
        }

        /// <summary>
        ///A test for ParseTags
        ///</summary>
        [Test()]
        public void ParseTagsTest()
        {
            string phrase = "a dog ate the cat";
            List<string> actual;
            actual = Utility.ParseTags(phrase);
            Assert.AreEqual(3, actual.Count);
            Assert.IsTrue(actual.Contains("dog"));
            Assert.IsTrue(!actual.Contains("a"));

        }

        /// <summary>
        /// Aka Int16
        /// </summary>
        [Test()]
        public void EncodeShortTest()
        {
            var minValue = Utility.EncodeNumeric(short.MinValue);
            Assert.AreEqual("067232", minValue);

            short decodedMinValue = Utility.DecodeNumericInt16(minValue);
            Assert.AreEqual(short.MinValue, decodedMinValue);

            var zeroValue = Utility.EncodeNumeric((short)0);
            Assert.AreEqual("100000", zeroValue);

            short decodedZeroValue = Utility.DecodeNumericInt16(zeroValue);
            Assert.AreEqual((short)0, decodedZeroValue);

            var maxValue = Utility.EncodeNumeric(short.MaxValue);
            Assert.AreEqual("132767", maxValue);

            short decodedMaxValue = Utility.DecodeNumericInt16(maxValue);
            Assert.AreEqual(short.MaxValue, decodedMaxValue);

        }

        /// <summary>
        /// Aka Int32
        /// </summary>
        [Test()]
        public void EncodeIntTest()
        {
            var minValue = Utility.EncodeNumeric(int.MinValue);
            Assert.AreEqual("07852516352", minValue);

            int decodedMinValue = Utility.DecodeNumericInt32(minValue);
            Assert.AreEqual(int.MinValue, decodedMinValue);

            var zeroValue = Utility.EncodeNumeric((int)0);
            Assert.AreEqual("10000000000", zeroValue);

            int decodedZeroValue = Utility.DecodeNumericInt32(zeroValue);
            Assert.AreEqual((int)0, decodedZeroValue);

            var maxValue = Utility.EncodeNumeric(int.MaxValue);
            Assert.AreEqual("12147483647", maxValue);

            int decodedMaxValue = Utility.DecodeNumericInt32(maxValue);
            Assert.AreEqual(int.MaxValue, decodedMaxValue);

        }
    }
}
